<%--
/**
* Copyright (c) 2000-2010 OSSR!ORG All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
--%>

<%@ include file="/html/init.jsp"%>

<portlet:defineObjects />
<liferay-theme:defineObjects />

<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%@ page import="org.ossr.portlets.pm.model.PrivateMessage" %>
<%@ page import="org.ossr.portlets.pm.service.PrivateMessageLocalServiceUtil" %>

<%@ page import="com.liferay.portal.kernel.dao.search.ResultRow" %>
<%@ page import="com.liferay.portal.kernel.dao.search.SearchContainer" %>
<%@ page import="com.liferay.portal.kernel.dao.search.SearchEntry" %>


<liferay-portlet:actionURL name="composeMessage" var="composeUrl">
</liferay-portlet:actionURL>

<aui:form name="composeMessage" action="<%= composeUrl.toString()%>" method="post">
<aui:button-row>
	<aui:button name="compose" type="submit" value="New Message"></aui:button>
</aui:button-row>
</aui:form>

<%
    // define list of headers we will use in the table
    List<String> headerNames = new ArrayList<String>();
    headerNames.add("subject");
    headerNames.add("creationDate");
    
    // create search container, used to display table
    SearchContainer searchContainer = new SearchContainer(renderRequest,
                                                        null, null,
                                                        SearchContainer.DEFAULT_CUR_PARAM,
                                                        SearchContainer.DEFAULT_DELTA,
                                                        portletURL,
                                                        headerNames,
                                                        "You have no messages");
    
    //portletURL.setParameter(searchContainer.getCurParam(), String.valueOf(searchContainer.getCurValue()));

    // get count of pets and list of pets to display on current page
    int messagesCount = PrivateMessageLocalServiceUtil.getPrivateMessagesCount();
    List<PrivateMessage> messages = PrivateMessageLocalServiceUtil
    										.getPrivateMessages(searchContainer.getStart(),
                                            					searchContainer.getEnd());

    // set count into search container
    searchContainer.setTotal(messagesCount);

    // fill table
    List<ResultRow> resultRows = searchContainer.getResultRows();
    for (int i=0; i < messages.size(); i++) {
        PrivateMessage message = messages.get(i);
        ResultRow row = new ResultRow(message, message.getMessageId(), i);

        row.addText(message.getSubject(), "");
        row.addText(message.getCreationDate().toString(),"");

        resultRows.add(row);
    }    

    // and finally display it
%>
<liferay-ui:search-iterator searchContainer="<%= searchContainer %>" />
